{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e198afc8",
   "metadata": {},
   "source": [
    "# 圆周卷积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "892f64c8",
   "metadata": {},
   "source": [
    "求序列x1=\\[1,2,3\\],x2=\\[2.3,1,2\\],N=5时的圆周卷积。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ef88d356",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAESCAYAAADzBx6nAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAASeUlEQVR4nO3dfZBddX3H8ffXPNiUpySwxiQVU3ygRqMGt5T41GARgtqaYRRs8YEHJ+jQR2uEqIg6OtSiTGewoUZwik+oWIjV0QZxjIRKiptGSJWmOi1BA+gqhFQmCg3f/nHOwmbdZO+Ge8+9+7vv18zO3nvOuef33d/c88kvv3PuuZGZSJLK9YRuFyBJ6iyDXpIKZ9BLUuEMekkqnEEvSYUz6NX3IuLIiJje7TqkTjHoVaSIWBERi0c9f01E/H5EjPeevwF42pjXXxQRF7bQzksiYrCF7X4rIs6OiGilfqmdDHoVpw7zjwC/MWrxi4DnA++LiNVjXvIr4KH6tR+MiFeNXjbO/j8aEW+qn74ZeHq9/C8i4gOjtntWRHwjIn4IbAR+Gzg5IrZFxFD9szUiPvL4/mLpwAx6lej1wHXALyPiD+plDwK/BP4G+ElEHB+VJwKPAK+MiNnAC4Cf1MseGbUNAPUUz4eAhfWixcC2epsXAX8fETPrdf8FnE31j8GNmfke4H7gtswczMxBYDVwVEd6Qao5L6miRMQzgLcCrwCuBG6PiCOBF1KF8+nAfcBvUgX6lfVLnwOcBSwFrgDmAQm8AfgRsLLe7rXAGuChiHgd8Ezg6lElfB3YAPw1EMDdwDF1bdPqZWP58XR1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CNeLYBH+xC322sfy/uhT7rxR/grVTTDxvrn4vtqwn7bA7wdeAmYC3wbPuspX7b2NSxOCU/GVtfRfJy4KbMHPeERivbdKOuXjbV62+SfTV59lnr2t1XUzLoJUmtm4pz9JKkSTDoJalwBr0kFc6gl6TCNfURfGlKi4j3Un2a+SVUl7+t8MoRTRWO6KXWPT0zXwpcB7ys28VIrTLopdZ9sv59FzDu7YulXmTQS617sNsFSAfDoJekwvnJWEkqnCN6SSqcQS9JhTPoJalwBr0kFc6gl6TCGfSSVDiDXpIK9/93ynuhyg0xCwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from math import *\n",
    "def conv_m(x,h):#线性卷积\n",
    " nx=len(x)\n",
    " nh=len(h)\n",
    " ny=nx+nh-1\n",
    " y=np.zeros(ny)#初始化\n",
    " for n in np.arange(ny):\n",
    "     y[n]=0\n",
    "     for m in np.arange(nh):\n",
    "         k=n-m+1\n",
    "         if k>=1 and k<=nx:\n",
    "             y[n]=y[n]+h[m]*x[k-1]#卷积\n",
    " return(y)\n",
    "def cir_con(x1,x2,N):#圆周卷积\n",
    "    nx1=np.arange(0,len(x1))\n",
    "    nx2=np.arange(0,len(x2))\n",
    "    x_1=np.append(x1,np.zeros(N-len(x1)))\n",
    "    h_1=np.append(x2,np.zeros(N-len(x2)))\n",
    "    y1=conv_m(x_1,h_1)#调用线性卷积函数\n",
    "    z_1=np.append(np.zeros(N),y1[0:N])\n",
    "    z_2=np.append((y1[N:2*N]),np.zeros(N))\n",
    "    z=z_1[0:2*N-1]+z_2[0:2*N-1]+y1[0:2*N-1]\n",
    "    y=z[0:N]\n",
    "    ny=np.arange(0,N)\n",
    "    plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "    plt.rcParams['axes.unicode_minus'] = False\n",
    "    plt.stem(y)\n",
    "    plt.title('线性卷积')\n",
    "    plt.xlabel('n')\n",
    "    plt.ylabel('y')\n",
    "    plt.show()\n",
    "cir_con(np.array([1,2,3]),np.array([2,3,1,2]),5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "167dfb77",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
